# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=dff
pkgver=183.d40d46b
pkgrel=6
pkgdesc='A Forensics Framework coming with command line and graphical interfaces.'
arch=('x86_64' 'aarch64')
url='https://github.com/arxsys/dff'
license=('GPL')
provides=('dff')
groups=('blackarch' 'blackarch-forensic')
depends=('python2' 'qt4' 'python-pyqt4' 'python2-pyqt4' 'python2-magic'
         'python2-apsw' 'python2-pillow6' 'poppler-qt4' 'python2-poppler-qt4'
         'ffmpeg' 'libbfio' 'libbde' 'libewf' 'libpff' 'libvshadow')
makedepends=('autoconf' 'automake' 'libtool' 'gettext' 'pkg-config' 'bison'
             'flex' 'swig' 'tre' 'pkg-config' 'libbfio' 'libbde' 'libewf'
             'libpff' 'libvshadow' 'git' 'cmake')
optdepends=(
  'python2-pefile: PE files support'
  'reglookup: registry hives support'
  'volatility: volatile memory support'
  'libreoffice-fresh: documents support'
)
options=()
source=("git+https://github.com/arxsys/$pkgname.git"
        'fixes.patch')
sha512sums=('SKIP'
            '25757b4fad24da09393d752f41c752a7ab4982c0af77431ead0885ddb9a7fd775dcd06934c15fc780fd2c163b4aea65d96d1ee6a68f96bc328b1adc2df6d2d89')

_gitname="dff"

pkgver() {
  cd "$_gitname"

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd "$_gitname"

  # patching to python2
  sed -i 's/\/python/\/python2/g' 'dff.py'
  sed -i 's/\/python/\/python2/g' 'dff-gui.py'
  sed -i 's/dff -g/dff-gui/g' 'ressources/dff.desktop'

  # pull submodules
  git submodule update --init --remote
  git submodule foreach git checkout develop

  # patching FindICU.cmake and EWF.cpp for compatibility.
  patch -Np1 -i "${srcdir}/fixes.patch"
}

build() {
  cd "$_gitname"

  # create build folder
  rm -rf build
  install -dm 755 build && cd build

  # python2 temporary alias
  install -dm 755 bin
  cp /usr/bin/python2 bin/python

  # build process
  PATH=./bin:$PATH cmake \
    -Wno-dev \
    -DCMAKE_INSTALL_PREFIX:FILEPATH=/usr \
    ..
  PATH=./bin:$PATH make
}

package() {
  cd "$_gitname/build"

  PATH=./bin:$PATH make INSTALL_ROOT="$pkgdir" DESTDIR="$pkgdir/" install

  mv "$pkgdir/usr/bin/dff" "$pkgdir/usr/bin/dff-cli"
  cp -r "$pkgdir/usr/lib/python2.7/site-packages/dff" "$pkgdir/usr/bin/"
}

